package com.bear.hospital.service.login.handle.strategy;

import com.bear.hospital.entity.LoginInfo;
import com.bear.hospital.mapper.AdminMapper;
import com.bear.hospital.pojo.Admin;
import com.bear.hospital.pojo.LoginMap;
import com.bear.hospital.service.admin.AdminService;
import com.bear.hospital.service.login.handle.LoginStrategy;
import com.bear.hospital.utils.JwtUtil;
import com.bear.hospital.utils.ResponseData;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author： zmwx
 * @Date： 2025/1/23 17:13
 * @Describe：
 */
@Component
public class LoginAdmin implements LoginStrategy {
    @Resource
    private AdminService adminService;
    @Resource
    AdminMapper adminMapper;

    @Override
    public String getType() {
        return "admin";
    }

    @Override
    public ResponseData login(LoginMap loginInfo) {

        Admin admin = adminService.login(loginInfo.getTid(), loginInfo.getPassword());
        if (ObjectUtils.isNotEmpty(admin)) {
            Map<String, String> map = new HashMap<>();
            map.put("aName", admin.getAName());
            map.put("aId", String.valueOf(admin.getAId()));
            map.put("userName",loginInfo.getUserName());
            String token = JwtUtil.getToken(map);
            map .put("token", token);
            map.put("loginUrl", loginInfo.getLoginUrl());

            return ResponseData.success("登录成功", map);
        } else {
            return ResponseData.fail("登录失败，密码或账号错误");
        }

    }

    @Override
    public ResponseData setProfilePhoto(LoginInfo loginInfo, String phoneUrl) {
        return null;
    }

    @Override
    public void addUser(LoginMap loginMap) {

    }
}
